﻿using FluentValidation;

namespace Services.Activity.WebApi.Request;

public class FilterActivityRequest
{
    public string? ActivityName { get; set; }
    public string? OrganizerName { get; set; }
    public int? ActivityType { get; set; }
    public DateTime? ActivityStartTime { get; set; }
    public DateTime? ActivityEndTime { get; set; }
    public string? ActivityBriefAddress { get; set; }
}
public class FilterActivityRequestValidator : AbstractValidator<FilterActivityRequest>
{
    public FilterActivityRequestValidator()
    {
        RuleFor(x => x.ActivityStartTime).Must(x =>
        {
            if (x.HasValue)
            {
                return x.Value > DateTime.Parse("2023/12/1");
            }
            else
            {
                return true;
            }
        }).WithMessage("筛选的日期必须大于2023年12月1日");
        RuleFor(x => x.ActivityEndTime).Must((x, b) =>
        {
            if (b.HasValue)
            {
                if (x.ActivityStartTime.HasValue)
                {
                    if (x.ActivityStartTime.Value > b.Value)
                    {
                        return false;
                    }
                }
            }
            return true;
        }).WithMessage("所筛选的活动起始时间不能晚于活动结束时间");
        RuleFor(x => x.ActivityType).Must(b =>
        {
            if (b.HasValue)
            {
                return b > 0 && b < 6;
            }
            return true;
        }
        ).WithMessage("活动的类型选择错误");
    }
}